//
// Ishtar C++ Utility Library
//
// Task Facility - Thread Pool Header
//

#ifndef __ISHTAR_TASK_THREAD_POOL_H
#define __ISHTAR_TASK_THREAD_POOL_H

#include <Ishtar/Ishtar.h>

#if defined( ISHTAR_COMPILER_HAS_PRAGMA_ONCE )
#pragma once
#endif

#include <Ishtar/ReferenceCounted.h>
#include <Ishtar/Task/TaskFwd.h>
#include <Ishtar/Task/Timer.h>
#include <Ishtar/Task/WorkExecutor.h>


namespace Ishtar
{

namespace Task
{

///////////////////////////////////////////////////////////////////////////////
//
// Thread Pool
//

class ThreadPoolImpl;

class ThreadPool : public WorkExecutor
{
public:
    void Startup( const std::string& name, Uint numThreads );
    void Shutdown();

    //
    // Dispatch Work to Pooled Threads
    //
    
    void SubmitWork( const Work& w );
    
    using WorkExecutor::SubmitWork;
    
    
    //
    // Accessors
    //
    
    Uint GetNumWaitingWorks() const;
    // returns the number of works which are submitted but not executed yet.

private:

    WorkExecutorImpl* GetImpl() const;

    InterlockedIntrusivePtr< ThreadPoolImpl > m_impl;
};

ISHTAR_REFERENCE_COUNTED_DECLARE( ThreadPoolImpl )


///////////////////////////////////////////////////////////////////////////////

} // namespace Task

} // namespace Ishtar

#endif // __ISHTAR_TASK_THREAD_POOL_H
